import React,{Component} from 'react';
import {
	Text,
  Image,
  StyleSheet,
  TouchableOpacity,
  View,ToastAndroid,Alert
} from 'react-native';
import Toast, {DURATION} from 'react-native-easy-toast'
import * as WeChat from 'react-native-wechat'
import UShare from '../share/share';
import SharePlatform from '../share/SharePlatform';
import {width} from '../common/common';
import {BASEURL} from '../api/api'
var IMG_URL =  BASEURL+'image/showImage?imageName=';
export default class ShareView extends Component{
  _shareWxFriend(){
		//ToastAndroid.show('分享',ToastAndroid.SHORT);
		let {item} = this.props;
		if(!item.mp4){
			this.props.toast.show("暂无视频，无法分享");
			return;
		}
		//alert(JSON.stringify(item))
		WeChat.isWXAppInstalled()
		.then((isInstalled) => {
			if (isInstalled) {
				
				WeChat.shareToTimeline({
					title:item.tempTitle,
					description: item.tempDesc,
					thumbImage: item.img.uri,
					type: 'news',
					webpageUrl: BASEURL+'share?tempId='+item.tempId, //item.mp4
				})
				.catch((error) => {
					Alert.alert(error.message);
				});
			} else {
				Alert.alert('请安装微信');
			}
		});
	}
	//微信好友分享
	_shareWxPerson(){
		let {item} = this.props;
		if(!item.mp4){
			this.props.toast.show("暂无视频，无法分享");
			return;
		}
		WeChat.isWXAppInstalled()
		.then((isInstalled) => {
				if (isInstalled) {
						WeChat.shareToSession({
						title:item.tempTitle,
						description: item.tempDesc,
						thumbImage: item.img.uri,
						type: 'news',
						webpageUrl: item.mp4
					})
				} else {
						Alert.alert('请安装微信');
				}
		});
	}
	_share3(){
		
	}
  render(){
    return(
      <View>
          <View style={styles.row}>
            <View style={{flexDirection:'row',}}>
              <Image style={styles.shareIcon} source={require('../images/mine/icon_share1.png')}/>
              <Text style={{marginLeft:10,}}>分享到</Text>
            </View>
            {this.props.hasClose?
              <TouchableOpacity onPress={this.props.handleClose}>
                <Image style={styles.closeImg} source={require('../images/reg/icon_close.png')}/>
              </TouchableOpacity>
              :null
            }
            
          </View>
          <View style={{flexDirection:'row',justifyContent:'space-around'}}>
            <ShareIcon text='朋友圈' imgStyle={{width:28,height:28}}  share={()=>this._shareWxFriend()}
              icon={require('../images/mine/icon_friend.png')}/>
            <ShareIcon text='微信' imgStyle={{width:34,height:28}}
              icon={require('../images/mine/icon_wechat.png')} share={()=>this._shareWxPerson()}/> 
            <ShareIcon text='朋友圈' imgStyle={{width:28,height:28}}
              icon={require('../images/mine/icon_zone.png')}/>
            <ShareIcon text='QQ' imgStyle={{width:24,height:28}}
              icon={require('../images/mine/icon_qq.png')}/>
            <ShareIcon text='新浪微博' imgStyle={{width:35,height:28}} share={()=>this._share3()}
              icon={require('../images/mine/icon_webo.png')}/>
          </View>
					<Toast ref="subToast" position='bottom' positionValue={200} />
      </View>
    )
  }
}
class ShareIcon extends Component{
  render(){
    imgStyle={
      width:width/10,
      height:width/10,
      resizeMode:'contain'
    }
    return(
      <TouchableOpacity style={{paddingTop:20,paddingBottom:20,alignItems:'center'}} onPress={this.props.share}>
        <Image style={[imgStyle,this.props.imgStyle]} source={this.props.icon}/>
        <Text style={{fontSize:12,color:'#888',padding:8,}}>{this.props.text}</Text>
      </TouchableOpacity>
    )
  }
}
const styles = StyleSheet.create({
  closeImg:{
    width:16,
    height:16,
    marginRight:15,
  },
  shareIcon:{
    width:20,
    height:20,
    marginLeft:10,
  },
  row:{
    flexDirection:'row',
    justifyContent:'space-between',
    alignItems:'center',
    borderBottomWidth:1,
    borderBottomColor:'#eee',
    paddingTop:10,
    paddingBottom:10,
  },
})